package com.zc.common.validator;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>Description : </p>
 *
 * @author : xuhongcao
 * @version : v1.0.0
 * @since : 31/3/2022
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserSaveReqDto {


    @ValidField(isNull = false, msg = "用户名不能为空", minLength = 5, maxLength = 10)
    private String userName;

    @ValidField(isNull = false, msg = "年龄不能为空", minNumber = 10, maxNumber = 90)
    private Integer age;

    @ValidField(isNull = false, msg = "邮件不能为空", regexType = RegexType.EMAIL)
    private String email;

    @ValidField(isNull = false, msg = "电话不能为空", regexType = RegexType.PHONENUMBER)
    private String phone;

    @ValidField(isNull = false, msg = "邮件不能为空,必须是邮件格式",regexType = RegexType.CHARACTER, regexExpression=RegexUtils.EMAIL_REGEX)
    private String custmerEmail;


    @ValidField(isNull = false, msg = "兴趣爱好不能为空", minNumber = 10, maxNumber = 90)
    private List<String> interests;

    public void setInterest(String interest) {
        if (Objects.isNull(interests)) {
            interests = new ArrayList<>();
        }
        interests.add(interest);
    }
}
